package com.yuwei.user

import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.tencent.mmkv.MMKV
import com.yuwei.base.BaseActivity
import com.yuwei.common.path.RouterPath
import com.yuwei.user.databinding.ActivityLoginBinding
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
@Route(path = RouterPath.MODULE_LOGIN_ACTIVITY)
class LoginActivity : BaseActivity<ActivityLoginBinding, UserViewModel>() {
    override fun initView() {
        binding.login.setOnClickListener {
            if(binding.etUsername.text.toString().isEmpty()||binding.etPassword.text.toString().isEmpty()){
                ToastUtils.showLong("用户名或密码不能为空")
                return@setOnClickListener
            }
            vm.login(binding.etUsername.text.toString(),binding.etPassword.text.toString())
        }
        binding.goRegister.setOnClickListener {
            ARouter.getInstance().build(RouterPath.MODULE_REGISTER_ACTIVITY).navigation()
        }
    }

    override fun initData() {
        vm.loginSuccess.observe(this){
            ToastUtils.showLong("欢迎,${it.username}")
            SPUtils.getInstance().put("token",it.token)
            ARouter.getInstance().build(RouterPath.MODULE_MAIN_ACTIVITY).navigation()
        }
    }

}